<include file="Public/min-header" />
<script type="text/javascript">
    window.UEDITOR_Admin_URL = "__ROOT__/Public/plugins/Ueditor/";
    var URL_upload = "{$URL_upload}";
    var URL_fileUp = "{$URL_fileUp}";
    var URL_scrawlUp = "{$URL_scrawlUp}";
    var URL_getRemoteImage = "{$URL_getRemoteImage}";
    var URL_imageManager = "{$URL_imageManager}";
    var URL_imageUp = "{$URL_imageUp}";
    var URL_getMovie = "{$URL_getMovie}";
    var URL_home = "{$URL_home}";    
</script>
<load href="__ROOT__/Public/plugins/Ueditor/ueditor.config.js"/>
<load href="__ROOT__/Public/plugins/Ueditor/ueditor.all.js"/>
<link href="__PUBLIC__/plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
<script src="__PUBLIC__/plugins/daterangepicker/moment.min.js" type="text/javascript"></script>
<script src="__PUBLIC__/plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<div class="wrapper">
    <include file="Public/breadcrumb"/>
    <section class="content ">
        <!-- Main content -->
        <div class="container-fluid">
            <div class="pull-right">
                <a href="javascript:history.go(-1)" data-toggle="tooltip" title="" class="btn btn-default" data-original-title="返回"><i class="fa fa-reply"></i></a>
           		<a href="javascript:;" class="btn btn-default" data-url="http://www.tp-shop.cn/Doc/Index/article/id/1012/developer/user.html" onclick="get_help(this)"><i class="fa fa-question-circle"></i> 帮助</a>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="fa fa-list"></i> 添加优惠券</h3>
                </div>
                <div class="panel-body ">   
                    <!--表单数据-->
                    <form action="" method="post" id="coupon">              
                        <!--通用信息-->
                    <div class="tab-content col-md-10" style="width: 100%;">                 	  
                        <div class="tab-pane active" id="tab_tongyong">                           
                            <table class="table table-bordered">
                                <tbody>
                                <tr>
                                    <td class="col-sm-2">优惠券名称：</td>
                                    <td class="col-sm-4">
                                        <input type="text" value="{$coupon.name}" class="form-control" id="name" name="name" >
                                        <span id="err_attr_name" style="color:#F00; display:none;"></span>                                        
                                    </td>
                                    <td class="col-sm-4">请填写优惠券名称
                                    </td>
                                </tr>  
                                <style>
									.coupon_sec2,.coupon_sec4{display: none;}
								</style>
                                <tr class="coupon_sec1">
                                    <td >优惠券面额：</td>
                                    <td >
                         				<input type="text" value="{$coupon.money}" class="form-control" id="money" name="money"  onpaste="this.value=this.value.replace(/[^\d.]/g,'')" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')"/>
                                    </td>
                                    <td>优惠券可抵扣金额</td>
                                </tr>  
                                <tr class="coupon_sec2">
                                    <td>优惠券折扣：</td>
                                    <td >
                         				<input type="text" value="{$coupon.expression}" class="form-control" id="expression" name="expression"  onpaste="this.value=this.value.replace(/[^\d.]/g,'')" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')"/>
                                    </td>
                                    <td>% 折扣值(1-100 如果打9折，请输入90)</td>
                                </tr> 
                                 
                                <tr class="coupon_sec3">
                                    <td>消费金额：</td>
                                    <td>
                      					<input type="text" value="{$coupon.condition}" class="form-control active" id="condition" name="condition"  onpaste="this.value=this.value.replace(/[^\d.]/g,'')" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" />
                                    </td>
                                    <td>订单需满足的最低消费金额(必需为整数)才能使用</td>
                                </tr>
                                 <!--<tr class="coupon_sec4">-->
                                    <!--<td>选择商品:</td>-->
                                    <!--<td>-->
                                        <!--<div class="form-group">-->
                                                                                 <!---->
	                                            <!--<a class="btn btn-primary" href="javascript:void(0);" onclick="selectGoods()" ><i class="fa fa-search"></i>添加商品</a>-->
                                           <!---->
                                                <!--<span id="err_goods" style="color:#F00; display:none;">请添加下单商品</span>-->
                                                                                      <!---->
                                        <!--</div>                                    -->
                                    <!--</td>-->
                                    <!--<td></td>-->
                                <!--</tr>-->
                                <!---->
                                <!---->
                                <!--<tr class="coupon_sec4">-->
                                    <!--<td colspan="3"> -->
                                       <!--<div class="form-group">-->
                                       		<!--<table class="table table-bordered">-->
                                       			<!--<thead>-->
                                       			<!--<tr>-->
                                       				<!--<th style="display:none">选择</th>-->
									                <!--<th class="text-left">商品名称</th>-->
									                <!--<th class="text-left">价格</th>         -->
									                <!--<th class="text-left">库存</th>								                -->
									                <!--<th class="text-left">操作</th>-->
									            <!--</tr>-->
									            <!--</thead>-->
									            <!--<tbody id="goods_list">-->
									            <!--<foreach name="prom_goods" item="vo">-->
									            	<!--<tr>-->
									            		<!--<td style="display:none"><input type="checkbox" name="goods_id[]" checked="checked" value="{$vo.goods_id}"/></td>-->
									                	<!--<td class="text-left">{$vo.goods_name}</td>            -->
									                	<!--<td class="text-left">{$vo.shop_price}</td>-->
									                	<!--<td class="text-left">{$vo.store_count}</td>-->
									                	<!--<td class="text-left"><a href="javascript:void(0)" onclick="javascript:$(this).parent().parent().remove();">删除</a></td>-->
									           		<!--</tr>-->
									           <!--</foreach>-->
									           <!--</tbody>-->
                                       		<!--</table>-->
                                         <!--</div>                                                                               -->
                                    <!--</td>-->
                                <!--</tr> -->
                                
                                <tr>
			                        <td>优惠券类型:</td>
			                        <td id="order-status" colspan="2">
			                            <input name="cateid" type="radio" value="1" <if condition="$coupon['cateid'] eq 1">checked</if> <if condition="$coupon['cateid'] eq ''">checked</if> >满减券
			                            <input name="cateid" type="radio" value="2" <if condition="$coupon['cateid'] eq 2">checked</if> >折扣券	
			                            <input name="cateid" type="radio" value="3" <if condition="$coupon['cateid'] eq 3">checked</if> >现金券	
			                         	 
			                        </td>
			                    </tr> 
                                <tr>
			                        <td>发放类型:</td>
			                        <td id="order-status"  colspan="2">
			                            <input name="type" type="radio" value="5" <if condition="$coupon['type'] eq 5">checked</if> <if condition="$coupon['type'] eq ''">checked</if>  >优惠券中心
			                           <!--   <input name="type" type="radio" value="1" <if condition="$coupon['type'] eq 1">checked</if> >用户发放	
			                         	 <input name="type" type="radio" value="0" <if condition="$coupon['type'] eq 0">checked</if> >面额模板
			                            <br >		                           
			                          <input name="type" type="radio" value="2" <if condition="$coupon['type'] eq 2">checked</if> >注册发放
			                            <input name="type" type="radio" value="3" <if condition="$coupon['type'] eq 3">checked</if> >邀请发放
			                            <input name="type" type="radio" value="4" <if condition="$coupon['type'] eq 4">checked</if> >线下发放 -->
			                        </td>
			                    </tr> 
			                    
			                    <style>
									#order-status input{vertical-align: middle;margin: 0 4px;}
								</style>
		                    
								<tr>
                                    <td>优惠券图片：</td>
                                    <td  colspan="2">
                                    
                                    <input type="button" value="上传图片" onclick="GetUploadify(1,'','coupon','call_back01');"/>
                                        <input type="text" class="input-sm"  name="original_img" id="original_img" value="{$coupon.original_img}"/>
                                        <if condition="$coupon['original_img'] neq null">
                                            &nbsp;&nbsp;
                                            <a target="_blank" href="{$coupon.original_img}" id="original_img2">
                                                <img width="25" height="25" src="/Public/images/image_icon.jpg">
                                            </a>
                                        </if>
                                        <span id="err_original_img" style="color:#F00; display:none;"></span>
                                    </td>
                                </tr>
			                    <tr>
			                    	<td>发放数量:</td>
			                    	<td><input type="text" value="{$coupon.createnum}" class="form-control" id="createnum" name="createnum" placeholder="0" onpaste="this.value=this.value.replace(/[^\d]/g,'')" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" /></td>
			                    	<td class="col-sm-4">发放数量限制(默认为0则无限制)</td>
			                    </tr>
			                    <tr class="timed">
			                        <td>发放起始日期:</td>
			                        <td>
			                            <div class="input-prepend input-group">
			                                <span class="add-on input-group-addon">
			                                      <i class="glyphicon glyphicon-calendar fa fa-calendar">  </i>
			                                </span>
			                                <input type="text" value="{$coupon.send_start_time|date='Y-m-d H:i:s',###}" class="form-control" id="send_start_time" name="send_start_time">
			                            </div>
			                        </td>
			                        <td class="col-sm-4"></td>
			                    </tr>
			
			                    <tr class="timed">
			                        <td>发放结束日期:</td>
			                        <td>
			                            <div class="input-prepend input-group">
			                                <span class="add-on input-group-addon">
			                                        <i class="glyphicon glyphicon-calendar fa fa-calendar"> </i>
			                                </span>
			                                <input type="text" value="{$coupon.send_end_time|date='Y-m-d H:i:s',###}" class="form-control" id="send_end_time" name="send_end_time">
			                            </div>
			                        </td>
			                        <td class="col-sm-4"></td>
			                    </tr>
					            <tr>
			                        <td>使用起始日期:</td>
			                        <td>
			                            <div class="input-prepend input-group">
			                                <span class="add-on input-group-addon">
			                                    <i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
			                                </span>
			                                <input type="text" value="{$coupon.use_start_time|date='Y-m-d H:i:s',###}" class="form-control" id="use_start_time" name="use_start_time">
			                            </div>
			                        </td>
			                        <td class="col-sm-4"></td>
			                    </tr> 
			                    <tr>
			                        <td>使用结束日期:</td>
			                        <td>
			                            <div class="input-prepend input-group">
			                                <span class="add-on input-group-addon">
			                                    <i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
			                                </span>
			                                <input type="text" value="{$coupon.use_end_time|date='Y-m-d H:i:s',###}" class="form-control" id="use_end_time" name="use_end_time">
			                            </div>
			                        </td>
			                        <td class="col-sm-4"></td>
			                    </tr>    
                               
                                 <tr>
				                    <td>优惠券描述：</td>
				                    <td  colspan="2">
							        <textarea class="span12 ckeditor" id="post_content" name="description" title="">
							            {$coupon.description}
							        </textarea>
				                    </td>
			                    </tr>                                 
                                </tbody> 
                                <tfoot>
                                	<tr>
                                	<td>
                                		<input type="hidden" name="id" value="{$coupon.id}">
                                	</td>
                                	<td class="col-sm-4"></td>
                                	<td class="text-right"><input class="btn btn-primary" type="button" value="保存" onclick="adsubmit()"></td>
                                	</tr>
                                </tfoot>                               
                            </table>
                        </div>                           
                    </div>              
			    	</form><!--表单数据-->
                </div>
            </div>
        </div>
    </section>
</div>

<script>
	
	
	var editor;
    $(function () {
        //具体参数配置在  editor_config.js 中
        var options = {
            zIndex: 999,
            initialFrameWidth: "100%", //初化宽度
            initialFrameHeight: 350, //初化高度
            focus: false, //初始化时，是否让编辑器获得焦点true或false
            maximumWords: 99999, removeFormatAttributes: 'class,style,lang,width,height,align,hspace,valign',//允许的最大字符数 'fullscreen',
            pasteplain: true, autoHeightEnabled: true,
            autotypeset: {
                mergeEmptyline: true,        //合并空行
                removeClass: true,           //去掉冗余的class
                removeEmptyline: false,      //去掉空行
                textAlign: "left",           //段落的排版方式，可以是 left,right,center,justify 去掉这个属性表示不执行排版
                imageBlockLine: 'center',    //图片的浮动方式，独占一行剧中,左右浮动，默认: center,left,right,none 去掉这个属性表示不执行排版
                pasteFilter: false,          //根据规则过滤没事粘贴进来的内容
                clearFontSize: false,        //去掉所有的内嵌字号，使用编辑器默认的字号
                clearFontFamily: false,      //去掉所有的内嵌字体，使用编辑器默认的字体
                removeEmptyNode: false,      //去掉空节点
                removeTagNames: {"font": 1},
                indent: false,               // 行首缩进
                indentValue: '0em'           //行首缩进的大小
            },
        	toolbars: [
                   ['fullscreen', 'source', '|', 'undo', 'redo','|', 'bold', 'italic', 'underline', 'fontborder',
                       'strikethrough', 'superscript', 'subscript','removeformat', 'formatmatch', 'autotypeset',
                       'blockquote', 'pasteplain', '|', 'forecolor','backcolor', 'insertorderedlist',
                       'insertunorderedlist', 'selectall', 'cleardoc', '|','rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
                       'customstyle', 'paragraph', 'fontfamily', 'fontsize','|', 'directionalityltr', 'directionalityrtl',
                       'indent', '|', 'justifyleft', 'justifycenter','justifyright', 'justifyjustify', '|', 'touppercase',
                       'tolowercase', '|', 'link', 'unlink', 'anchor', '|','imagenone', 'imageleft', 'imageright', 'imagecenter',
                       '|', 'insertimage', 'emotion', 'insertvideo','attachment', 'map', 'gmap', 'insertframe',
                       'insertcode', 'webapp', 'pagebreak', 'template','background', '|', 'horizontal', 'date', 'time',
                       'spechars', 'wordimage', '|','inserttable', 'deletetable','insertparagraphbeforetable', 'insertrow', 'deleterow',
                       'insertcol', 'deletecol', 'mergecells', 'mergeright','mergedown', 'splittocells', 'splittorows',
                       'splittocols', '|', 'print', 'preview', 'searchreplace']
               ]
        };
        editor = new UE.ui.Editor(options);
        editor.render("post_content");
    });
	
$('input[type="radio"]').click(function(){
    if($(this).val() == 0){
    	$('.timed').hide();
    }else{
    	$('.timed').show();
    }
})



function adsubmit(){
	var submitcateidval =$(":radio[name='cateid']:checked").val();

	
	if($('#name').val() ==''){
		alert('优惠名称不能为空');
		return false;
	}
	
	if(submitcateidval==1)
		 {
			 if($('input[name=money]').val() =='' || $('input[name=condition]').val() ==''){
				alert('优惠券面额及消费金额不能为空');
				return false;
			}
		 }
	 else if(submitcateidval==2)
		 {
			 
			 if($('input[name=expression]').val() ==''){
				 
				alert('折扣优惠不能为空');
				return false;
			 }
		 }
	 else if(submitcateidval==3)
		 {
			 
			 if($('input[name=money]').val() ==''){
				 
				alert('优惠券面额不能为空');
				return false;
			 }
			 
//			var pg = [];
//			//过滤选择重复商品
//			$('input[name*="goods_id"]').each(function(i,o){
//				pg.push($(o).val());
//			});
//			if(pg.length==0){
//
//				alert('请指定现金券对应商品');
//				return false;
//			}
		 }
	
	$('#coupon').submit();
}


 $(":radio[name='cateid']").click(function(){
  var cateidval =$(":radio[name='cateid']:checked").val();
	 if(cateidval==1)
		 {
			 $('.coupon_sec1,.coupon_sec3').show();
			 $('.coupon_sec2,.coupon_sec4').hide();
		 }
	 else if(cateidval==2)
		 {
			 $('.coupon_sec2').show();
			 $('.coupon_sec1,.coupon_sec3,.coupon_sec4').hide();
		 }
	 else if(cateidval==3)
		 {

//			 $('.coupon_sec4,.coupon_sec1').show();
			 $('.coupon_sec1').show();
			 $('.coupon_sec2,.coupon_sec3').hide();
		 }


});

    function call_back01(fileurl_tmp){
        $("#original_img").val(fileurl_tmp);
    	$("#original_img2").attr('href', fileurl_tmp);
    }

$(function(){
    data_pick('send_start_time');
    data_pick('send_end_time');
    data_pick('use_start_time');
    data_pick('use_end_time');
    $('input[type="radio"]:checked').trigger('click');
})


function selectGoods(){
	var goods_id = []; 
	//过滤选择重复商品
	$('input[name*="goods_id"]').each(function(i,o){
		goods_id.push($(o).val());
	});
    var url = '/index.php?m=Admin&c=Coupon&a=search_coupon_goods&goods_id='+goods_id+'&t='+Math.random();
    layer.open({
        type: 2,
        title: '选择商品',
        shadeClose: true,
        shade: 0.3,
        area: ['70%', '80%'],
        content: url, 
    });
}
    
	
	
function call_back(table_html)
{
	layer.closeAll('iframe');
	$('#goods_list').append(table_html);
}
	
function data_pick(id){
    var myDate = new Date();
    $('#'+id).daterangepicker({
    	format:"YYYY-MM-DD HH:mm:ss",
        singleDatePicker: true,
        showDropdowns: true,
        minDate:myDate.getFullYear()+'-'+myDate.getMonth()+'-'+myDate.getDate(),
        maxDate:'2030-01-01',
		timePicker : true, //是否显示小时和分钟  
        timePickerIncrement:1,//time选择递增数
		timePicker12Hour : false, //是否使用12小时制来显示时间 		
        locale : {
            applyLabel : '确定',
            cancelLabel : '取消',
            fromLabel : '起始时间',
            toLabel : '结束时间',
            customRangeLabel : '自定义',
            daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
            monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月','七月', '八月', '九月', '十月', '十一月', '十二月' ],
            firstDay : 1
        }
    });
}
</script>
</body>
</html>